package leetcode.doublepointer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

//344. 反转字符串
public class ReverseString {
    public static void main(String[] args) {
        char[] s = {'h','e','l'};
        reverseString2(s);
        System.out.println(Arrays.toString(s));
    }
    public static void reverseString(char[] s) {
        int p =0;
        int q = s.length-1;
        while (p<q){
            char tmp = s[p];
            s[p] = s[q];
            s[q] = tmp;
            p++;
            q--;
        }
    }

    // API
    public static void reverseString2(char[] s) {
        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i < s.length; i++) {
            list.add(s[i]);
        }
        Collections.reverse(list);
//        System.out.println(list);
        for (int i = 0; i < list.size(); i++) {
            s[i] = list.get(i);
        }
    }
}
